#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    Init();
    initConnect();

}

Widget::~Widget()
{
    delete ui;
}

void Widget::Init()
{
    ui->rBtn_dec->setChecked(true);
    emit ui->slider_red->valueChanged(1); // 给textEdit加上背景颜色
}

void Widget::initConnect()
{
    connect(ui->slider_blue,SIGNAL(valueChanged(int)),
            this,SLOT(on_slider_red_valueChanged(int)));
    connect(ui->slider_green,SIGNAL(valueChanged(int)),
            this,SLOT(on_slider_red_valueChanged(int)));
    connect(ui->slider_alpha,SIGNAL(valueChanged(int)),
            this,SLOT(on_slider_red_valueChanged(int)));
}

void Widget::on_slider_red_valueChanged(int value)
{
    Q_UNUSED(value)  // 不需要语句结束符
    QColor color;
    int R = ui->slider_red->value();
    int G = ui->slider_green->value();
    int B = ui->slider_blue->value();
    int alpha = ui->slider_alpha->value();
    color.setRgb(R,G,B,alpha);
    QPalette pal = ui->textEdit->palette();
    pal.setColor(QPalette::Base,color);
    ui->textEdit->setPalette(pal);
}


void Widget::on_dial_valueChanged(int value)
{
    ui->lcdNumber->display(value);
}

void Widget::on_rBtn_dec_clicked()
{
    ui->lcdNumber->setDigitCount(3);
    ui->lcdNumber->setDecMode();
}

void Widget::on_rBtn_bin_clicked()
{
    ui->lcdNumber->setDigitCount(8);
    ui->lcdNumber->setBinMode();
}

void Widget::on_rBtn_oct_clicked()
{
    ui->lcdNumber->setDigitCount(4);
    ui->lcdNumber->setOctMode();
}

void Widget::on_rBtn_hex_clicked()
{
    ui->lcdNumber->setDigitCount(3);
    ui->lcdNumber->setHexMode();
}


void Widget::on_slider_hor_valueChanged(int value)
{
    Q_UNUSED(value)
    ui->scrollbar_hor->setValue(value);
    ui->progressBar_hor->setValue(value);
}

void Widget::on_scrollbar_hor_valueChanged(int value)
{
    Q_UNUSED(value)
    ui->slider_hor->setValue(value);
    ui->progressBar_hor->setValue(value);
}

void Widget::on_slider_vec_valueChanged(int value)
{
    Q_UNUSED(value)
    ui->scrollbar_vec->setValue(value);
    ui->progressbar_vec->setValue(value);
}

void Widget::on_scrollbar_vec_valueChanged(int value)
{
    Q_UNUSED(value)
    ui->slider_vec->setValue(value);
    ui->progressbar_vec->setValue(value);
}
